package com.hk.service.impl;

import org.springframework.stereotype.Service;

import com.hk.commons.HqlFilter;
import com.hk.commons.StringHelper;
import com.hk.commons.entity.City;
import com.hk.commons.entity.Province;
import com.hk.dao.base.impl.BaseServiceImpl;
import com.hk.service.sys.ICity;

@Service
public class CityImpl extends BaseServiceImpl<City> implements ICity {

	@Override
	public City findById(Integer id) {
		return getById(id);
	}

	@Override
	public void add(City model) {

		super.save(model);
	}

	@Override
	public City delete(Integer id) {
		City model = new City();
		model.setId(id);
		delete(model);
		return model;
	}

	@Override
	public Boolean existById(Integer CityId) {

		City City = getById(CityId);
		return City != null;
	}

	@Override
	public String getCityNameById(Integer CityId) {
		String CityName = "";
		City City = getById(CityId);
		if (City != null) {
			CityName = City.getCityName();
		}
		return CityName;
	}

	@Override
	public Integer getCityIdByCode(String cityCode) {

		Integer CityId = null;
		if (StringHelper.isNotEmpty(cityCode)) {
			HqlFilter hqlFilter = new HqlFilter();
			hqlFilter.addEQFilter("cityCode", cityCode);

			City City = getByFilter(hqlFilter);
			if (City != null) {
				CityId = City.getId();
			}
		}
		return CityId;
	}
	
	 
}
